<!doctype html>
<title>window.open: subresource loading</title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script>
promise_test(() => {
  const readAndReportBlobContents = () => {
    const xhr = new XMLHttpRequest;
    xhr.open('GET', self.blobUrl, true);
    xhr.responseType = 'blob';
    xhr.onload = e => {
      const reader = new FileReader;
      reader.onloadend = e => { self.reportBlobContents(reader.result); };
      reader.readAsText(xhr.response);
    };
    xhr.send();
  };

  const kBlobText = 'hello i am blob';
  const target = self.open();
  const blob = new Blob([kBlobText], {type: 'text/plain'});
  const blobUrl = URL.createObjectURL(blob);
  return new Promise((resolve, reject) => {
    target.blobUrl = blobUrl;
    target.reportBlobContents = resolve;
    target.document.write('<script>(' + readAndReportBlobContents + ')();</' +
        'script>\n');
  }).then(readBlobText => {
    assert_equals(readBlobText, kBlobText);
  });
}, 'Check that new blank windows can load subresources.');
</script>
